package cn.edu.scau.cmi.mazhuanglong.fxml;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.mazhuanglong.adapter.AdapterOfClass;
import cn.edu.scau.cmi.mazhuanglong.adapter.Student;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class AdapterController {
	@FXML
	private ResourceBundle resources;

	@FXML
	private URL location;

	@FXML
	private TextField idString2;

	@FXML
	private TextArea output1;

	@FXML
	private TextField idString1;

	@FXML
	private TextArea output2;

	@FXML
	private TextField nameString1;

	@FXML
	private TextField nameString2;

	private List<Student> studentList1 = new ArrayList<Student>();
	private List<Student> studentList2 = new ArrayList<Student>();
	@FXML
	void addStudentClass(ActionEvent event) {
		String name = nameString1.getText();
		String idstr = idString1.getText();
		int id = Integer.valueOf(idstr).intValue();
	
		studentList1.add(new Student(id, name));

		AdapterOfClass ofclass = new AdapterOfClass();
		studentList1 = ofclass.SortStudent(studentList1);

		String out = new String();
		for (int i = 0; i < studentList1.size(); i++) {
			out = out + studentList1.get(i).getId() + "  " + studentList1.get(i).getName() + "\n";
		}
		output1.setText(out);

	}
	@FXML
	void addStudentObject(ActionEvent event) {
		String name = nameString2.getText();
		String idstr = idString2.getText();
		int id = Integer.valueOf(idstr).intValue();
		studentList2.add(new Student(id, name));

		AdapterOfClass ofobject = new AdapterOfClass();
		studentList2 = ofobject.SortStudent(studentList2);

		String out = new String();
		for (int i = 0; i < studentList2.size(); i++) {
			out = out + studentList2.get(i).getId() + "  " + studentList2.get(i).getName() + "\n";
		}
		output2.setText(out);
	}
}
